/*     */ package com.zimbra.cs.redolog.op;
/*     */ 
/*     */ import com.zimbra.common.calendar.ICalTimeZone;
/*     */ import com.zimbra.common.calendar.TimeZoneMap;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.cs.mailbox.MailboxOperation;
/*     */ import com.zimbra.cs.mailbox.Metadata;
/*     */ import com.zimbra.cs.mailbox.calendar.Invite;
/*     */ import com.zimbra.cs.mailbox.calendar.Util;
/*     */ import com.zimbra.cs.mime.ParsedMessage;
/*     */ import com.zimbra.cs.redolog.RedoLogInput;
/*     */ import com.zimbra.cs.redolog.RedoLogOutput;
/*     */ import com.zimbra.cs.redolog.Version;
/*     */ import java.io.IOException;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class CreateInvite
/*     */   extends RedoableOp
/*     */   implements CreateCalendarItemRecorder, CreateCalendarItemPlayer
/*     */ {
/*     */   private int mCalendarItemId;
/*  39 */   private String mCalendarItemPartStat = "NE";
/*     */   private Invite mInvite;
/*     */   private int mFolderId;
/*     */   private byte[] mData;
/*     */   private boolean mPreserveExistingAlarms;
/*     */   private boolean mDiscardExistingInvites;
/*     */   private boolean mAddRevision;
/*     */   
/*     */   public CreateInvite() {
/*  48 */     super(MailboxOperation.CreateInvite);
/*     */   }
/*     */   
/*     */   public CreateInvite(int mailboxId, Invite inv, int folderId, byte[] data, boolean preserveExistingAlarms, boolean discardExistingInvites, boolean addRevision)
/*     */   {
/*  53 */     this();
/*  54 */     setMailboxId(mailboxId);
/*  55 */     this.mInvite = inv;
/*  56 */     this.mFolderId = folderId;
/*  57 */     this.mData = data;
/*  58 */     this.mPreserveExistingAlarms = preserveExistingAlarms;
/*  59 */     this.mDiscardExistingInvites = discardExistingInvites;
/*  60 */     this.mAddRevision = addRevision;
/*     */   }
/*     */   
/*     */   protected String getPrintableData() {
/*  64 */     StringBuilder sb = new StringBuilder("calItemId=").append(this.mCalendarItemId);
/*  65 */     sb.append(", calItemPartStat=").append(this.mCalendarItemPartStat);
/*  66 */     sb.append(", folder=").append(this.mFolderId);
/*  67 */     sb.append(", dataLen=").append(this.mData != null ? this.mData.length : 0);
/*  68 */     ICalTimeZone localTz = this.mInvite.getTimeZoneMap().getLocalTimeZone();
/*  69 */     sb.append(", localTZ=").append(Util.encodeAsMetadata(localTz).toString());
/*  70 */     sb.append(", inv=").append(Invite.encodeMetadata(this.mInvite).toString());
/*  71 */     sb.append(", preserveExistingAlarms=").append(this.mPreserveExistingAlarms);
/*  72 */     sb.append(", discardExistingInvites=").append(this.mDiscardExistingInvites);
/*  73 */     sb.append(", addRevision=").append(this.mAddRevision);
/*  74 */     return sb.toString();
/*     */   }
/*     */   
/*     */   protected void serializeData(RedoLogOutput out) throws IOException {
/*  78 */     out.writeInt(this.mCalendarItemId);
/*  79 */     if (getVersion().atLeast(1, 1))
/*  80 */       out.writeUTF(this.mCalendarItemPartStat);
/*  81 */     out.writeInt(this.mFolderId);
/*  82 */     if (getVersion().atLeast(1, 0))
/*  83 */       out.writeShort((short)-1);
/*  84 */     out.writeBoolean(true);
/*     */     
/*     */ 
/*  87 */     int dataLen = this.mData != null ? this.mData.length : 0;
/*  88 */     out.writeInt(dataLen);
/*  89 */     if (dataLen > 0) {
/*  90 */       out.write(this.mData);
/*     */     }
/*     */     
/*  93 */     ICalTimeZone localTz = this.mInvite.getTimeZoneMap().getLocalTimeZone();
/*  94 */     out.writeUTF(Util.encodeAsMetadata(localTz).toString());
/*  95 */     out.writeUTF(Invite.encodeMetadata(this.mInvite).toString());
/*     */     
/*  97 */     if (getVersion().atLeast(1, 22)) {
/*  98 */       out.writeBoolean(this.mPreserveExistingAlarms);
/*  99 */       out.writeBoolean(this.mDiscardExistingInvites);
/*     */     }
/* 101 */     if (getVersion().atLeast(1, 23))
/* 102 */       out.writeBoolean(this.mAddRevision);
/*     */   }
/*     */   
/*     */   protected void deserializeData(RedoLogInput in) throws IOException {
/* 106 */     this.mCalendarItemId = in.readInt();
/* 107 */     if (getVersion().atLeast(1, 1))
/* 108 */       this.mCalendarItemPartStat = in.readUTF();
/* 109 */     this.mFolderId = in.readInt();
/* 110 */     if (getVersion().atLeast(1, 0))
/* 111 */       in.readShort();
/* 112 */     in.readBoolean();
/*     */     
/*     */ 
/* 115 */     int dataLen = in.readInt();
/* 116 */     if (dataLen > 0) {
/* 117 */       this.mData = new byte[dataLen];
/* 118 */       in.readFully(this.mData);
/*     */     }
/*     */     try
/*     */     {
/* 122 */       ICalTimeZone localTz = Util.decodeTimeZoneFromMetadata(new Metadata(in.readUTF()));
/*     */       
/* 124 */       this.mInvite = Invite.decodeMetadata(getMailboxId(), new Metadata(in.readUTF()), null, localTz);
/*     */     }
/*     */     catch (ServiceException ex) {
/* 127 */       ex.printStackTrace();
/* 128 */       throw new IOException("Cannot read serialized entry for CreateInvite " + ex.toString());
/*     */     }
/*     */     
/* 131 */     if (getVersion().atLeast(1, 22)) {
/* 132 */       this.mPreserveExistingAlarms = in.readBoolean();
/* 133 */       this.mDiscardExistingInvites = in.readBoolean();
/*     */     } else {
/* 135 */       this.mPreserveExistingAlarms = false;
/* 136 */       this.mDiscardExistingInvites = false;
/*     */     }
/* 138 */     if (getVersion().atLeast(1, 23)) {
/* 139 */       this.mAddRevision = in.readBoolean();
/*     */     } else
/* 141 */       this.mAddRevision = false;
/*     */   }
/*     */   
/*     */   public void setCalendarItemAttrs(int appointmentId, int folderId) {
/* 145 */     this.mCalendarItemId = appointmentId;
/* 146 */     this.mFolderId = folderId;
/*     */   }
/*     */   
/*     */   public int getCalendarItemId() {
/* 150 */     return this.mCalendarItemId;
/*     */   }
/*     */   
/*     */   public String getCalendarItemPartStat() {
/* 154 */     return this.mCalendarItemPartStat;
/*     */   }
/*     */   
/*     */   public void setCalendarItemPartStat(String partStat) {
/* 158 */     this.mCalendarItemPartStat = partStat;
/*     */   }
/*     */   
/*     */   public int getFolderId() {
/* 162 */     return this.mFolderId;
/*     */   }
/*     */   
/*     */   public void redo() throws Exception {
/* 166 */     Mailbox mbox = MailboxManager.getInstance().getMailboxById(getMailboxId());
/* 167 */     ParsedMessage pm = null;
/* 168 */     if ((this.mData != null) && (this.mData.length > 0))
/* 169 */       pm = new ParsedMessage(this.mData, Long.valueOf(getTimestamp()), mbox.attachmentsIndexingEnabled());
/* 170 */     mbox.addInvite(getOperationContext(), this.mInvite, this.mFolderId, pm, this.mPreserveExistingAlarms, this.mDiscardExistingInvites, this.mAddRevision);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/redolog/op/CreateInvite.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */